import { Component, OnDestroy } from '@angular/core';

import { DoubleShopProductService } from './double.shop.product.service';

import { ProductBase } from '../../product/product.base';

import { Util } from '../../../utils/util';


import { ToastyService } from '../../../modules/ng2-toasty';

@Component({
  selector: 'double-shop-product',
  templateUrl: './double.shop.product.html',
  providers: [DoubleShopProductService]
})

export class DoubleShopProductComponent extends ProductBase {

  shop: any;

  param: any = {
    uid: '',
    rows: 10,
    start: 0
  };

  // 列表
  public columns: Array<any> = [
    {
      title: '商品',
      name: 'brandName',
      sort: false,
      class: 'productTh'
    },
    {
      title: '标题',
      name: 'categoryName',
      sort: false,
      class: 'titleTh'
    },
    {
      title: '品牌',
      name: 'shopNum',
      sort: false
    },
    {
      title: '销售量',
      name: 'sellAmount',
      sort: true
    },
    {
      title: '预售价',
      name: 'priceYuShou',
      sort: true
    },
    {
      title: '定金',
      name: 'dingJin',
      sort: true
    }
  ];
  constructor(public util: Util, public service: DoubleShopProductService, public toastyService: ToastyService) {
    super(service, util, toastyService);

    this.shop = this.util.sessionStore().get('shopDetail');

    // console.log(this.brandInfo);
    this.param.uid = this.shop.uid;

    this.getHttp(this.param);

  }

  ngOnDestroy() {
    if (this.busy) {
      this.busy.unsubscribe();
    }

  }

  date: any;
  getHttp(param) {

    this.busy = this.service.getDoubleShopProduct(param).subscribe((res: any) => {

      this.vm.table.products = res.data.value;

      this.vm.table.count = res.data.count;

      if (this.vm.table.products.length > 0) {
        this.date = this.vm.table.products[0].modifyTime;
      }
    }, (err: any) => {

    });
  }



  export() {

    let json: any = {
      uid: this.shop.uid,
      rows: 1000,
      start: 0
    };

    let dim = ['modifyTime', 'numberId', 'title', 'picUrl', 'loc', 'propertyValue', 'brandName', 'sellAmount', 'priceYuShou', 'dingJin', 'diKou', 'uid'];

    let dimText = ['时间', '宝贝Id', '宝贝标题', '宝贝图片链接', '地址', '属性', '品牌名', '销售量', '预售价', '定金', '抵扣', '店铺id'];

    let fileName = this.shop.shopName + "全部预售宝贝";

    this.productExport(json, dim, dimText, fileName);
  }

}
